package com.changhongit.config.security;

import org.springframework.context.annotation.Configuration;
import org.springframework.web.servlet.config.annotation.CorsRegistry;
import org.springframework.web.servlet.config.annotation.WebMvcConfigurer;

@Configuration
public class WebCorsConfig implements WebMvcConfigurer {
    @Override
    public void addCorsMappings(CorsRegistry registry) {
        registry
                //允许访问的路径
                .addMapping("/**")
                //配置请求来源
                .allowedOrigins("http://localhost:8080","http://localhost:8000","http://localhost:9000")
                //允许方法
                .allowedMethods("GET","POST","DELETE","PUT","OPTION")
                //允许请求头
                //.allowedHeaders()
                //允许携带参数
                .allowCredentials(true)
                //允许超时时间
                .maxAge(3600)
        ;
    }
}
